<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no, viewport-fit=cover" />
        <link rel="icon" type="image/png" href="/favicon.png" />
        <meta name="renderer" content="webkit" />
        <meta name="force-rendering" content="webkit" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>登录中</title>
        <link rel="stylesheet" href="/src/common/mdcss/freestyle.css" />
        <script src="/src/common/mdjs/freestyle.js"></script>
    </head>

    <body>
        <script>
            var __api_server__ = <%- apiServer %>;
            var getRequest = () => {
                var encodeUrl = new URL(location.href.replace('#', encodeURIComponent('#')));
                var search = encodeUrl.search.replace('?', '');
                var theRequest = new Object();
                var strs = search.split('&');
                for (var i = 0; i < strs.length; i++) {
                    var result = strs[i].split('=');
                    theRequest[result[0]] = decodeURIComponent(result[1]);
                }
                return theRequest;
            };

            var request = getRequest();
            var xhr = new XMLHttpRequest();

            xhr.open('POST', __api_server__.main + 'ExternalPortal/ExportalSSO', true);
            xhr.setRequestHeader('Content-Type', 'application/json');

            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var response = JSON.parse(xhr.responseText);
                        if (response.data.code === 0) {
                            location.href = '/portal/app/' + request.appId;
                        } else {
                            alert(response.data.message);
                        }
                    } else {
                        alert('服务异常，登录失败!');
                    }
                }
            };

            xhr.send(JSON.stringify(request));
        </script>
    </body>
</html>
